var App = function() {
    
	var upload,jcrop;
    
    return {
        /**
         * 依赖组件
         */
        requires : ['Fw.Jcrop'],
        /**
         * 初始化
         * 应用入口
         */
        init : function(require) {
            this.initJcrop();
            this.initEvents();
        },
        /**
         * 加载图片裁剪
         */
        initJcrop: function(){
        	var me = this;
        	jcrop = new Fw.Jcrop({
        		contentEl: 'jcrop',
        		opt: {
        			allowMove:true, //选区可拖动
	        		allowSelect: false,
	        		allowResize: true,
	        		aspectRatio:1,
	        		setSelect: [0,0,100,100]
        		}
        	});
        },
        /**
         * 初始化事件
         */
        initEvents : function() {
        	$('#btn').on('click', Fw.bind(this.onClick, this));
        	//图片裁剪区域选变换时触发
        	jcrop.on('change', this.showCoords, this);
        	//图片裁剪区域选中时触发
        	jcrop.on('select', this.showCoords, this);
        	//裁剪成功后
        	jcrop.on('success', this.onSuccess, this);
        	//裁剪失败后
        	jcrop.on('error', this.onFailure, this);
        },
        /**
         * 简单的事件处理程序，响应自onChange,onSelect事件，按照上面的Jcrop调用
         */
        showCoords: function(obj){
//        	console.log(obj)
        },
        onSuccess: function(jcrop,data, result){
        	alert(data)
        },
        onFailure: function(jcrop, status, textStatus, error){
        	alert('error')
        },
        onClick: function(){
        	var fileId = '';
        	this.i = this.i || 0;
        	if(this.i == 1){
        		this.i = 0;
        		fileId = 'test';
        	} else {
        		this.i = 1;
        		fileId = 'A10DE74E-EB9A-4ECB-8B0A-0450143F686B';
        	}
        	jcrop.setFileId(fileId);
        }
    };
}();

Fw.onReady(App); 